<?php

/**
 * Description of Css
 *
 * @author ecv
 */
class Css extends Tmpl {

    public function add_browser_prefixes()
    {
        if ($this->load_file())
        {
            if (!isset($this->output) || empty($this->output))
            {
                $this->output = $this->source;
            }

            /**
             * this should find the css3 properties specified in
             * regex['pattern'] and adds the webkit and gecko ones.
             * Result is stored in our $this->output variable.
             * I'm not the regex guru, but my tests were okay. Should
             * work with common properties and values. Not at all sure if this
             * could be a security risk
             */
            $regex = array(
                'pattern' => array(
                    '/[ ]*[^\S](display)[^\S]*[ ]*:{1}[ ]*[^\S](box)[ ]*;{1}/',
                    '/[ ]*[^\S](box-orient)[^\S]*[ ]*:{1}[ ]*([-\w]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](box-align)[^\S]*[ ]*:{1}[ ]*([-\w]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](box-flex)[^\S]*[ ]*:{1}[ ]*([-\w]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](box-ordinal-group)[^\S]*[ ]*:{1}[ ]*([-\d]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](box-sizing)[^\S]*[ ]*:{1}[ ]*([-\w]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](box-shadow)[^\S]*[ ]*:{1}[ ]*([^;]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](border-radius)[^\S]*[ ]*:{1}[ ]*([^;]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](transform)[^\S]*[ ]*:{1}[ ]*([^;]+)+[ ]*;{1}/',
                    '/[ ]*[^\S](transition)[^\S]*[ ]*:{1}[ ]*([^;]+)+[ ]*;{1}/',
                ),
                'replacement' => array(
                    '$1: -webkit-$2; $1: -moz-$2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                    '-webkit-$1: $2; -moz-$1: $2; $1: $2;',
                )
            );

            $this->output = preg_replace(
                $regex['pattern'], $regex['replacement'], $this->output
            );

            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

}
